
import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: []
}

const mutations = {
  setRoutes(state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes]
  }
}

const actions = {
  // 获取到用户信息后 根据用户的menus数组中的数据 过滤当前用户具备哪些动态路由权限(页面权限)
  filteRoutes(context, menus) {
    const routes = []
    menus.forEach(key => {
      routes.push(...asyncRoutes.filter(item => item.name === key))
    })
    context.commit('setRoutes', [...routes, { path: '*', component: () => import('@/views/404'), hidden: true }])
    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
